package md.lanjing.com.module_wallet.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;


import com.lxh.baselibray.constant.Constant;

import md.lanjing.com.module_wallet.R;
import md.lanjing.com.module_wallet.api.WalletApiService;
import md.lanjing.com.module_wallet.bean.RealNameResponce;
import md.lanjing.com.module_wallet.bean.TransferAccountRequest;
import md.lanjing.com.module_wallet.bean.TransferAccountResponce;
import retrofit2.Call;
import retrofit2.Response;

public class TransferContact {
    public static class TransferPresent extends BasePresent<ITransferView> {
        public void transfer(final Context context, int type, double money, String payPassword, String toPhone){
            WalletApiService service= ServiceGenerator.createService(WalletApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            TransferAccountRequest request=new TransferAccountRequest(userId,type,money, Md5Utils.stringToMD5(payPassword),toPhone);
            service.transferAccount(request).enqueue(new NetCallBack<TransferAccountResponce>() {
                @Override
                public void onSuccess(Call<TransferAccountResponce> call, Response<TransferAccountResponce> response) {
                    if (getView()!=null){
                        getView().getTransferData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,context.getString(R.string.request_failed));
                }
            });

        }

        public void getRealNameByPhone(final Context context, String phone){
            WalletApiService service= ServiceGenerator.createService(WalletApiService.class);
            service.getRealName(phone).enqueue(new NetCallBack<RealNameResponce>() {
                @Override
                public void onSuccess(Call<RealNameResponce> call, Response<RealNameResponce> response) {
                    if (getView()!=null){
                        getView().getRealNameByPhoneData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,context.getString(R.string.request_failed));
                }
            });

        }
    }

    public interface ITransferView extends IBaseView {
        void getTransferData(Response<TransferAccountResponce> response);
        void getRealNameByPhoneData(Response<RealNameResponce> response);
    }


}
